package com.example.asus.pictures;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private TextView textView;
    private ImageView imgStar;
    private Button btnNext;
    private int[]starimgs={R.drawable.yi,R.drawable.gong,R.drawable.song,
            R.drawable.nan, R.drawable.gray};
    private int index;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView=findViewById(R.id.text1);

        textView.setText("Hello World!");
        textView.setTextColor(Color.BLUE);

        imgStar=findViewById(R.id.imgStar);
        btnNext=findViewById(R.id.btnNext);

        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //数组 + 下标
                index=(index+1) % starimgs.length;
                imgStar.setImageResource(starimgs[index]);
            }
        });
    }
}

